package com.tf_cut.backend.person.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.google.common.collect.Lists;
import com.tf_cut.backend.common.pojo.PageInfo;
import com.tf_cut.backend.common.pojo.Result;
import com.tf_cut.backend.person.service.PersonService;
import com.tf_cut.backend.person.vo.PersonAndAccountVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/backend/admin/person/info")
public class PersonInfoController {

    @Autowired
    private PersonService personService;

    @PostMapping("/list")
    public String queryPersonInfoList(String json) {
        PersonAndAccountVo personAndAccountVo = JSON.parseObject(json, PersonAndAccountVo.class);
        Result<List<PersonAndAccountVo>> result;
        try {
            PageInfo<PersonAndAccountVo> personAndAccountVoPageInfo = personService.queryPersonInfoList(personAndAccountVo);
            return JSON.toJSONString(personAndAccountVoPageInfo, SerializerFeature.WriteDateUseDateFormat);
        } catch (Exception e) {
            log.error("queryPersonInfoList error:{}", e.getMessage(), e);
            result = Result.of(Lists.newArrayList());
            result.setMsg(e.getMessage());
            result.setFlag(false);
        }
        return JSON.toJSONString(result, SerializerFeature.WriteDateUseDateFormat);
    }
    
    /**
     * 在admin包platform包下的GrantController类下的queryPersonInfo方法
     * @param page
     * @param rows
     * @param sellerName
     * @param serviceName
     * @param startDate
     * @param endDate
     * @return
     */
    @RequestMapping("/queryPersonInfo")
    public String queryPersonInfo(@RequestParam("page") int page,@RequestParam("rows") int rows,@RequestParam("personName") String personName,@RequestParam("startDate") String startDate,
            @RequestParam("endDate") String endDate,@RequestParam("cardStatus") String cardStatus,@RequestParam("cardCode") String cardCode,@RequestParam("iphone") String iphone) {
    	PageInfo<PersonAndAccountVo> sellerBillAndConsigneeVoPageInfo = personService.queryPersonInfo(page,rows,personName,startDate,endDate,cardStatus,cardCode,iphone);
    	return JSON.toJSONString(sellerBillAndConsigneeVoPageInfo, SerializerFeature.WriteDateUseDateFormat);
    	
    }
    
    
    @PostMapping("/queryByPersonId")
    public String queryByPersonId(String personId){
    	
		return JSON.toJSONString(personService.queryByPersonId(personId));
    	
    }

}
